<?php
require_once 'bbs/include/common.inc.php';
require_once 'classes/include.php';
require_once 'classes/class.phpmailer.php';	//包函邮件发送类  
require_once 'customer_config.php';	

//require_once "function.php"; 

//$_POST	= daddslashes($_POST);
//$_GET	= daddslashes($_GET);


$act = $_GET['act'];

switch($act)
{
	case 'applicant':
		applicant();
		break;
	
	case 'send_email':
		send_email();
		break;
	
	default:
		break;
}

//报名入库
function applicant()
{
	global $db;
	
	if($_POST)
	{	
		//验证码
		$validate_code = $_POST['validate_code'];
		
		session_start();
//echo $validate_code.'----'.$_SESSION['randcode'];
		//验证码错误
		if($validate_code != $_SESSION['randcode'])
		{
			echo 2;
			exit;
		}
		
		//报名信息入库			
		$applicant_username	= $_POST['applicant_username'];
		$sex 				= $_POST['sex'];
		$birth_date 		= $_POST['birth_date'];
		$company 			= $_POST['company'];
		$mobile 			= $_POST['mobile'];
		$email 				= $_POST['email'];
		$remark 			= $_POST['remark'];
		$submit_time 		= date('Y-m-d H:i:s', time());				
		
		$sql = "INSERT INTO applicant_info (applicant_username, sex, birth_date, company, mobile, email, remark, submit_time) values ('".$applicant_username."', '".$sex."', '".$birth_date."', '".$company."', '".$mobile."', '".$email."', '".$remark."', '".$submit_time."')";

		$insert_res = $db->query($sql);
		
		echo $insert_res;
	}
}


  
//邮件发送  
function send_email() 
{	
	global $email_config;
	
	$tomail				= $_POST['email'];
	$applicant_username	= $_POST['applicant_username'];
	
//$tomail = 'wangnannew@gmail.com';
	
	$email_config
	
	$mail_host	= $email_config['mail_host'];	// SMTP 服务器  
	$send_user	= $email_config['send_user'];	// 用户名 
	$send_pass	= $email_config['send_pass'];	// 密码
	$fromName	= $email_config['fromName'];	// 发信人别名
	$frommail	= $email_config['frommail'];	// 发信人  

	$subject	= '恭喜'.$applicant_username.'报名成功';
	$body		= "报名成功报名成功报名成功报名成功报名成功";
	$ccmail		='';
	
	$mail = new PHPMailer();  
	$mail->IsSMTP();					// 经smtp发送  
	$mail->Host     = $mail_host;       // SMTP 服务器  
	$mail->SMTPAuth = true;             // 打开SMTP 认证  
	$mail->Username = $send_user;    	// 用户名  
	$mail->Password = $send_pass;       // 密码  
	$mail->From     = $frommail;        // 发信人  
	$mail->FromName = $fromName;        // 发信人别名  
	$mail->AddAddress($tomail);         // 收信人  
	if(!empty($ccmail)){  
		$mail->AddCC($ccmail);          // cc收信人  
	}  

	$mail->WordWrap = 50;  
	$mail->CharSet = 'UTF-8'; 
	//$mail->Encoding = 'base64';
	//$mail->IsHTML(true);                // 以html方式发送

	$mail->Subject  = $subject;         // 邮件标题
	$mail->Body     = $body;            // 邮件内空  
	//$mail->AltBody  =  "请使用HTML方式查看邮件。";  
	echo $mail->Send();  
}  
  

?>